﻿using System;
using System.Drawing;
using MUnit;

namespace Maze
{
    class TestPlayer
    {
        private SQ[,] squares = {{ SQ.W, SQ.O },
                                 { SQ.O, SQ.O }};
        private Board board;
        private PathFinder pathFinder;
        private Player player;

        private Point startSquare = new Point(1, 0);

        [Setup]
        void Setup()
        {
            // This will be run once before each test method
            this.board = new Board(this.squares);
            this.pathFinder = new PathFinder(this.board);
            this.player = new Player(this.startSquare, this.pathFinder);
        }

        [Test]
        void Creation()
        {
            Verify.Equals(MazeForm.SquareToPixels(this.startSquare), this.player.Location);
        }

        [Test]
        void Update()
        {
            Point destination = new Point(1, 1);
            this.player.GoToSquare(destination);
            this.player.Update(this.board);

            Verify.Equals(MazeForm.SquareToPixels(destination), this.player.Location);
        }

        [Test]
        void GoTo()
        {

            this.player.GoToSquare(new Point(0, 1));
            this.player.Update(this.board);
            Verify.Equals(MazeForm.SquareToPixels(new Point(1, 1)), this.player.Location);

            this.player.Update(this.board);
            Verify.Equals(MazeForm.SquareToPixels(new Point(0, 1)), this.player.Location);
        }

        [Test]
        void GoToTwice()
        {
            this.player.GoToSquare(new Point(1, 1));
            this.player.GoToSquare(new Point(0, 1));
            this.player.Update(this.board);
            Verify.Equals(new Point(1, 1), MazeForm.PixelsToSquare(this.player.Location));
            this.player.Update(this.board);
            Verify.Equals(new Point(0, 1), MazeForm.PixelsToSquare(this.player.Location));
        }

        [Test]
        void GoToWithSmallSteps()
        {
            int divider = 10;
            this.player.GoToSquare(new Point(1, 1));
            this.player.Update(divider, this.board);
            Point point = MazeForm.SquareToPixels(this.startSquare);
            point.Y += (MazeForm.SquareSize.Height / divider);
            Verify.Equals(point, this.player.Location);
        }


        [Test]
        void SquareIsIncludedInPath()
        {
            Point square = new Point(1, 1);
            this.player.GoToSquare(square);

            Verify.Assert(this.player.IncludedInPath(square));
        }

        [TearDown]
        void TearDown()
        {
            // This will be run once after each test method
        }
    }
}
